﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using AntikCompta.Data;

namespace AntikCompta
{
    public partial class NewExercice : Form
    {
        private Exercice mNewExercice;
        private DataMng mDataMng;

        internal NewExercice(ref DataMng aDataMng, ref Exercice aNewEx)
        {
            mNewExercice = aNewEx;
            mDataMng = aDataMng;
            InitializeComponent();

            SAI_Annee.Text = DateTime.Now.Year+"";
        }

        private void button2_Click(object sender, EventArgs e)
        {
            DialogResult = DialogResult.Cancel;
            Close();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            if (SAI_Annee.Text.Length <= 0)
            {
                MessageBox.Show("Tu n'as pas donné d'année");
                return;
            }

            int annee = SAI_Annee.IntValue;
            Exercice ex;
            if (mDataMng.GetExercice(annee, out ex) == true)
                MessageBox.Show("Cet exercice existe déjà");
            else
            {
                mNewExercice.Annee = annee;
                DialogResult = DialogResult.OK;
                Close();
            }
        }

    }
}
